import CryptoJS from 'crypto-js';
import localStorage from "localStorage";

/** 加密登录密码 */
export const encrypt = (plaintText) => {
  const CRYPTOJSKEY = 'cmbCampus0722000';
  const options = {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7,
  };
  const key = CryptoJS.enc.Utf8.parse(CRYPTOJSKEY);
  const encryptedData = CryptoJS.AES.encrypt(plaintText, key, options);
  const encryptedBase64Str = encryptedData.toString(); return encryptedBase64Str;
};

/** 做本地存储 */
export const setToken = (token) => {
  return localStorage.setItem('token', JSON.stringify(token))
}

export const getToken = () => {
    return  JSON.parse(localStorage.getItem('token'))
}

export const removeToken = () => {
  return localStorage.removeItem('token')
}

/** 表格状态装换 */
export const changeStatus = (status) => {
  const num = Number(status)
  switch (num) {
    case 1:
      return '待审核'
    case 2:
      return '进行中'
    case 3:
      return '未开始'
    case 4:
      return '已驳回'
    case 5:
      return '已结束'
    case 6:
      return '已结束'
    default:
        return num
  }
}
